const Mock = require("mockjs");

const Random = Mock.Random;

let result = {
    code: 200,
    msg: 'success',
    data: null
};


Mock.mock('/captcha', 'get', () => {
    result.data = {
        token: Random.string(32),
        captchaImg: Random.dataImage('100x40', 'p7n5w')
    }
    return result;
});

Mock.mock('/login', 'post', () => {
    //mock无法往header中存入数据

    return result;
});

Mock.mock('/logout', 'post', () => {

    return result;
});

Mock.mock('/sys/user/Info', 'get', () => {
    //mock无法往header中存入数据
    result.data = {
        id: "1",
        username: "test",
        avatar: "https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
    }
    return result;
});

Mock.mock(RegExp('/sys/menu/list/children'), "get", (options) => {
    let children = [];
    let data = JSON.parse(options.body);
    if (data.id === '2') {
        children = [{
            "id": 9,
            "created": "2021-01-17T21:48:32",
            "updated": null,
            "state": 1,
            "parentId": 2,
            "name": "添加用户",
            "path": null,
            "permCode": "sys:user:save",
            "component": null,
            "type": 2,
            "icon": null,
            "orderNum": 1,
            "children": []
        },
            {
                "id": 10,
                "created": "2021-01-17T21:49:03",
                "updated": "2021-01-17T21:53:04",
                "state": 1,
                "parentId": 2,
                "name": "修改用户",
                "path": null,
                "permCode": "sys:user:update",
                "component": null,
                "type": 2,
                "icon": null,
                "orderNum": 2,
                "children": []
            },
            {
                "id": 11,
                "created": "2021-01-17T21:49:21",
                "updated": null,
                "state": 1,
                "parentId": 2,
                "name": "删除用户",
                "path": null,
                "permCode": "sys:user:delete",
                "component": null,
                "type": 2,
                "icon": null,
                "orderNum": 3,
                "children": []
            },
            {
                "id": 12,
                "created": "2021-01-17T21:49:58",
                "updated": null,
                "state": 1,
                "parentId": 2,
                "name": "分配角色",
                "path": null,
                "permCode": "sys:user:role",
                "component": null,
                "type": 2,
                "icon": null,
                "orderNum": 4,
                "children": []
            },
            {
                "id": 13,
                "created": "2021-01-17T21:50:36",
                "updated": null,
                "state": 1,
                "parentId": 2,
                "name": "重置密码",
                "path": null,
                "permCode": "sys:user:repass",
                "component": null,
                "type": 2,
                "icon": null,
                "orderNum": 5,
                "children": []
            }
        ]
    } else if (data.id === '3') {
        children = [
            {
                "id": 7,
                "created": "2021-01-15T23:02:25",
                "updated": "2021-01-17T21:53:14",
                "state": 0,
                "parentId": 3,
                "name": "添加角色",
                "path": "",
                "permCode": "sys:role:save",
                "component": "",
                "type": 2,
                "icon": "",
                "orderNum": 1,
                "children": []
            },
            {
                "id": 14,
                "created": "2021-01-17T21:51:14",
                "updated": null,
                "state": 1,
                "parentId": 3,
                "name": "修改角色",
                "path": null,
                "permCode": "sys:role:update",
                "component": null,
                "type": 2,
                "icon": null,
                "orderNum": 2,
                "children": []
            },
            {
                "id": 15,
                "created": "2021-01-17T21:51:39",
                "updated": null,
                "state": 1,
                "parentId": 3,
                "name": "删除角色",
                "path": null,
                "permCode": "sys:role:delete",
                "component": null,
                "type": 2,
                "icon": null,
                "orderNum": 3,
                "children": []
            },
            {
                "id": 16,
                "created": "2021-01-17T21:52:02",
                "updated": null,
                "state": 1,
                "parentId": 3,
                "name": "分配权限",
                "path": null,
                "permCode": "sys:role:perm",
                "component": null,
                "type": 2,
                "icon": null,
                "orderNum": 5,
                "children": []
            }
        ]
    } else if (data.id === '4') {
        children = [
            {
                "id": 17,
                "created": "2021-01-17T21:53:53",
                "updated": "2021-01-17T21:55:28",
                "state": 1,
                "parentId": 4,
                "name": "添加菜单",
                "path": null,
                "permCode": "sys:menu:save",
                "component": null,
                "type": 2,
                "icon": null,
                "orderNum": 1,
                "children": []
            },
            {
                "id": 18,
                "created": "2021-01-17T21:56:12",
                "updated": null,
                "state": 1,
                "parentId": 4,
                "name": "修改菜单",
                "path": null,
                "permCode": "sys:menu:update",
                "component": null,
                "type": 2,
                "icon": null,
                "orderNum": 2,
                "children": []
            },
            {
                "id": 19,
                "created": "2021-01-17T21:56:36",
                "updated": null,
                "state": 1,
                "parentId": 4,
                "name": "删除菜单",
                "path": null,
                "permCode": "sys:menu:delete",
                "component": null,
                "type": 2,
                "icon": null,
                "orderNum": 3,
                "children": []
            }
        ]
    }
    result.data = children;

    return result;
});

Mock.mock('/sys/menu/list', 'get', () => {
    //mock无法往header中存入数据
    result.data = [
        {
            "id": 1,
            "created": "2021-01-15T18:58:18",
            "updated": "2021-01-15T18:58:20",
            "state": 1,
            "parentId": 0,
            "name": "系统管理",
            "path": "",
            "permCode": "sys:manage",
            "component": "",
            "type": 0,
            "icon": "el-icon-s-operation",
            "orderNum": 1,
            "children": [
                {
                    "id": 2,
                    "created": "2021-01-15T19:03:45",
                    "updated": "2021-01-15T19:03:48",
                    "state": 1,
                    "parentId": 1,
                    "name": "用户管理",
                    "path": "/sys/users",
                    "permCode": "sys:user:list",
                    "component": "sys/User",
                    "type": 1,
                    "icon": "el-icon-s-custom",
                    "orderNum": 1,
                    "children": [
                        {
                            "id": 9,
                            "created": "2021-01-17T21:48:32",
                            "updated": null,
                            "state": 1,
                            "parentId": 2,
                            "name": "添加用户",
                            "path": null,
                            "permCode": "sys:user:save",
                            "component": null,
                            "type": 2,
                            "icon": null,
                            "orderNum": 1,
                            "children": []
                        },
                        {
                            "id": 10,
                            "created": "2021-01-17T21:49:03",
                            "updated": "2021-01-17T21:53:04",
                            "state": 1,
                            "parentId": 2,
                            "name": "修改用户",
                            "path": null,
                            "permCode": "sys:user:update",
                            "component": null,
                            "type": 2,
                            "icon": null,
                            "orderNum": 2,
                            "children": []
                        },
                        {
                            "id": 11,
                            "created": "2021-01-17T21:49:21",
                            "updated": null,
                            "state": 1,
                            "parentId": 2,
                            "name": "删除用户",
                            "path": null,
                            "permCode": "sys:user:delete",
                            "component": null,
                            "type": 2,
                            "icon": null,
                            "orderNum": 3,
                            "children": []
                        },
                        {
                            "id": 12,
                            "created": "2021-01-17T21:49:58",
                            "updated": null,
                            "state": 1,
                            "parentId": 2,
                            "name": "分配角色",
                            "path": null,
                            "permCode": "sys:user:role",
                            "component": null,
                            "type": 2,
                            "icon": null,
                            "orderNum": 4,
                            "children": []
                        },
                        {
                            "id": 13,
                            "created": "2021-01-17T21:50:36",
                            "updated": null,
                            "state": 1,
                            "parentId": 2,
                            "name": "重置密码",
                            "path": null,
                            "permCode": "sys:user:repass",
                            "component": null,
                            "type": 2,
                            "icon": null,
                            "orderNum": 5,
                            "children": []
                        }
                    ]
                },
                {
                    "id": 3,
                    "created": "2021-01-15T19:03:45",
                    "updated": "2021-01-15T19:03:48",
                    "state": 1,
                    "parentId": 1,
                    "name": "角色管理",
                    "path": "/sys/roles",
                    "permCode": "sys:role:list",
                    "component": "sys/Role",
                    "type": 1,
                    "icon": "el-icon-rank",
                    "orderNum": 2,
                    "children": [
                        {
                            "id": 7,
                            "created": "2021-01-15T23:02:25",
                            "updated": "2021-01-17T21:53:14",
                            "state": 0,
                            "parentId": 3,
                            "name": "添加角色",
                            "path": "",
                            "permCode": "sys:role:save",
                            "component": "",
                            "type": 2,
                            "icon": "",
                            "orderNum": 1,
                            "children": []
                        },
                        {
                            "id": 14,
                            "created": "2021-01-17T21:51:14",
                            "updated": null,
                            "state": 1,
                            "parentId": 3,
                            "name": "修改角色",
                            "path": null,
                            "permCode": "sys:role:update",
                            "component": null,
                            "type": 2,
                            "icon": null,
                            "orderNum": 2,
                            "children": []
                        },
                        {
                            "id": 15,
                            "created": "2021-01-17T21:51:39",
                            "updated": null,
                            "state": 1,
                            "parentId": 3,
                            "name": "删除角色",
                            "path": null,
                            "permCode": "sys:role:delete",
                            "component": null,
                            "type": 2,
                            "icon": null,
                            "orderNum": 3,
                            "children": []
                        },
                        {
                            "id": 16,
                            "created": "2021-01-17T21:52:02",
                            "updated": null,
                            "state": 1,
                            "parentId": 3,
                            "name": "分配权限",
                            "path": null,
                            "permCode": "sys:role:perm",
                            "component": null,
                            "type": 2,
                            "icon": null,
                            "orderNum": 5,
                            "children": []
                        }
                    ]
                },
                {
                    "id": 4,
                    "created": "2021-01-15T19:03:45",
                    "updated": "2021-01-15T19:03:48",
                    "state": 1,
                    "parentId": 1,
                    "name": "菜单管理",
                    "path": "/sys/menus",
                    "permCode": "sys:menu:list",
                    "component": "sys/Menu",
                    "type": 1,
                    "icon": "el-icon-menu",
                    "orderNum": 3,
                    "children": [
                        {
                            "id": 17,
                            "created": "2021-01-17T21:53:53",
                            "updated": "2021-01-17T21:55:28",
                            "state": 1,
                            "parentId": 4,
                            "name": "添加菜单",
                            "path": null,
                            "permCode": "sys:menu:save",
                            "component": null,
                            "type": 2,
                            "icon": null,
                            "orderNum": 1,
                            "children": []
                        },
                        {
                            "id": 18,
                            "created": "2021-01-17T21:56:12",
                            "updated": null,
                            "state": 1,
                            "parentId": 4,
                            "name": "修改菜单",
                            "path": null,
                            "permCode": "sys:menu:update",
                            "component": null,
                            "type": 2,
                            "icon": null,
                            "orderNum": 2,
                            "children": []
                        },
                        {
                            "id": 19,
                            "created": "2021-01-17T21:56:36",
                            "updated": null,
                            "state": 1,
                            "parentId": 4,
                            "name": "删除菜单",
                            "path": null,
                            "permCode": "sys:menu:delete",
                            "component": null,
                            "type": 2,
                            "icon": null,
                            "orderNum": 3,
                            "children": []
                        }
                    ]
                }
            ]
        },
        {
            "id": 5,
            "created": "2021-01-15T19:06:11",
            "updated": null,
            "state": 1,
            "parentId": 0,
            "name": "系统工具",
            "path": "",
            "permCode": "sys:tools",
            "component": null,
            "type": 0,
            "icon": "el-icon-s-tools",
            "orderNum": 2,
            "children": [
                {
                    "id": 6,
                    "created": "2021-01-15T19:07:18",
                    "updated": "2021-01-18T16:32:13",
                    "state": 1,
                    "parentId": 5,
                    "name": "数字字典",
                    "path": "/sys/dicts",
                    "permCode": "sys:dict:list",
                    "component": "sys/Dict",
                    "type": 1,
                    "icon": "el-icon-s-order",
                    "orderNum": 1,
                    "children": []
                }
            ]
        }
    ];
    return result;
});

Mock.mock('/sys/menu/nav', 'get', () => {
        let nav = [
            {
                path: '/book',
                name: 'Book',
                title: '图书信息管理',
                component: 'Book',
                icon: 'el-icon-menu'
            },
            {
                index: '1',
                name: 'SysMana',
                title: '系统管理',
                icon: 'el-icon-s-operation',
                component: '',
                children: [
                    {
                        path: '/sys/users',
                        name: 'Users',
                        title: '用户管理',
                        component: 'sys/User',
                        icon: 'el-icon-s-custom',
                    }, {
                        path: '/sys/roles',
                        name: 'Roles',
                        title: '角色管理',
                        component: 'sys/Role',
                        icon: 'el-icon-rank',
                    }, {
                        path: '/sys/menus',
                        name: 'Menus',
                        title: '菜单管理',
                        component: 'sys/Menu',
                        icon: 'el-icon-menu',
                    },
                ]
            },
            {
                index: '2',
                name: 'SysTool',
                title: '系统工具',
                component: '',
                icon: 'el-icon-s-tools',
                children: [
                    {
                        path: '2-2',
                        name: 'SysDict',
                        title: '数字字典',
                        component: '',
                        icon: 'el-icon-s-order',
                    }
                ]
            }

        ]

        let permissions = ['sys:manage', 'sys:menu:save', 'sys:user:update','sys:role:delete','sys:role:perm','sys:user:role']

        result.data = {
            nav: nav,
            perms: permissions
        }

        return result;
    }
);

Mock.mock('/sys/menu/save', 'post', () => {

    return result;
});

Mock.mock('/sys/menu/update', 'post', () => {

    return result;
});

Mock.mock(RegExp('/sys/menu/delete/*'), 'post', () => {

    return result;
});

Mock.mock(RegExp('/sys/menu/info/*'), 'get', () => {
    result.data = {
        "id": 2,
        "created": "2021-01-15T19:03:45",
        "updated": "2021-01-15T19:03:48",
        "state": 1,
        "parentId": 1,
        "name": "用户管理",
        "path": "/sys/users",
        "permCode": "sys:user:list",
        "component": "sys/User",
        "type": 1,
        "icon": "el-icon-s-custom",
        "orderNum": 1,
    }

    return result;
});

Mock.mock(RegExp('/sys/role/list.*'), 'get', () => {
    //mock无法往header中存入数据
    result.data = {
        "records": [
            {
                "id": 3,
                "created": "2021-01-04T10:09:14",
                "updated": "2021-01-30T08:19:52",
                "state": 1,
                "name": "普通用户",
                "code": "normal",
                "remark": "只有基本查看功能",
                "menuIds": []
            },
            {
                "id": 6,
                "created": "2021-01-16T13:29:03",
                "updated": "2021-01-17T15:50:45",
                "state": 1,
                "name": "超级管理员",
                "code": "admin",
                "remark": "系统默认最高权限，不可以编辑和任意修改",
                "menuIds": []
            }
        ],
        "total": 2,
        "size": 10,
        "current": 1,
        "orders": [],
        "optimizeCountSql": true,
        "hitCount": false,
        "countId": null,
        "maxLimit": null,
        "searchCount": true,
        "pages": 1
    };
    return result;
});
Mock.mock('/sys/role/save', 'post', () => {

    return result;
});

Mock.mock('/sys/role/update', 'post', () => {

    return result;
});

Mock.mock(RegExp('/sys/role/delete/*'), 'post', () => {

    return result;
});
Mock.mock(RegExp('/sys/role/perm/*'), 'post', () => {

    return result;
});

Mock.mock(RegExp('/sys/role/info/*'), 'get', () => {
    result.data = {
        "id": 3,
        "created": "2021-01-04T10:09:14",
        "updated": "2021-01-30T08:19:52",
        "state": 1,
        "name": "普通用户",
        "code": "normal",
        "remark": "只有基本查看功能",
        "menuIds": [2]
    };

    return result;
});

Mock.mock(RegExp('/sys/user/list.*'), 'get', () => {
    //mock无法往header中存入数据
    result.data = {
        "records": [
            {
                "id": 1,
                "created": "2021-01-12T22:13:53",
                "updated": "2021-01-16T16:57:32",
                "state": 1,
                "username": "admin",
                "password": "$2a$10$om4bTNo5k98xsNs6iCMl7eRI6biXXK6m.sxLF91kb3a0kbziLW3GG",
                "avatar": "https://image-1300566513.cos.ap-guangzhou.myqcloud.com/upload/images/5a9f48118166308daba8b6da7e466aab.jpg",
                "email": "123@qq.com",
                "phone": "21124241231",
                "city": "广州",
                "lastLogin": "2020-12-30T08:38:37",
                "roles": [
                    {
                        "id": 6,
                        "created": "2021-01-16T13:29:03",
                        "updated": "2021-01-17T15:50:45",
                        "state": 1,
                        "name": "超级管理员",
                        "code": "admin",
                        "remark": "系统默认最高权限，不可以编辑和任意修改",
                        "menuIds": []
                    },
                    {
                        "id": 3,
                        "created": "2021-01-04T10:09:14",
                        "updated": "2021-01-30T08:19:52",
                        "state": 1,
                        "name": "普通用户",
                        "code": "normal",
                        "remark": "只有基本查看功能",
                        "menuIds": []
                    }
                ]
            },
            {
                "id": 2,
                "created": "2021-01-30T08:20:22",
                "updated": "2021-01-30T08:55:57",
                "state": 1,
                "username": "test",
                "password": "$2a$10$0ilP4ZD1kLugYwLCs4pmb.ZT9cFqzOZTNaMiHxrBnVIQUGUwEvBIO",
                "avatar": "https://image-1300566513.cos.ap-guangzhou.myqcloud.com/upload/images/5a9f48118166308daba8b6da7e466aab.jpg",
                "email": "test@qq.com",
                "phone": "12424122131",
                "city": "广州",
                "lastLogin": null,
                "roles": [
                    {
                        "id": 3,
                        "created": "2021-01-04T10:09:14",
                        "updated": "2021-01-30T08:19:52",
                        "state": 1,
                        "name": "普通用户",
                        "code": "normal",
                        "remark": "只有基本查看功能",
                        "menuIds": []
                    }
                ]
            }
        ],
        "total": 2,
        "size": 10,
        "current": 1,
        "orders": [],
        "optimizeCountSql": true,
        "hitCount": false,
        "countId": null,
        "maxLimit": null,
        "searchCount": true,
        "pages": 1
    };
    return result;
});
Mock.mock('/sys/user/save', 'post', () => {

    return result;
});

Mock.mock('/sys/user/update', 'post', () => {

    return result;
});

Mock.mock(RegExp('/sys/user/delete'), 'post', () => {

    return result;
});
Mock.mock(RegExp('/sys/user/role/*'), 'post', () => {

    return result;
});
Mock.mock('/sys/user/repass', 'post', () => {

    return result;
});

Mock.mock(RegExp('/sys/user/info/*'), 'get', () => {
    result.data = {
        "id": 2,
        "created": "2021-01-30T08:20:22",
        "updated": "2021-01-30T08:55:57",
        "state": 1,
        "username": "test",
        "password": "$2a$10$0ilP4ZD1kLugYwLCs4pmb.ZT9cFqzOZTNaMiHxrBnVIQUGUwEvBIO",
        "avatar": "https://image-1300566513.cos.ap-guangzhou.myqcloud.com/upload/images/5a9f48118166308daba8b6da7e466aab.jpg",
        "email": "test@qq.com",
        "city": "广州",
        "lastLogin": null,
        "roles": [
            {
                "id": 3,
                "created": "2021-01-04T10:09:14",
                "updated": "2021-01-30T08:19:52",
                "state": 1,
                "name": "普通用户",
                "code": "normal",
                "remark": "只有基本查看功能",
                "menuIds": []
            }
        ]
    };

    return result;
});
